import 'package:hive/hive.dart';

part 'report.g.dart';

/// 举报类型枚举
@HiveType(typeId: 6)
enum ReportType {
  @HiveField(0)
  post,    // 帖子举报
  @HiveField(1)
  user,    // 用户举报
  @HiveField(2)
  chat,    // 聊天举报
}

/// 举报原因枚举
@HiveType(typeId: 7)
enum ReportReason {
  @HiveField(0)
  sexuallyExplicit,  // Report Sexually Explicit Material
  @HiveField(1)
  spam,              // Report spam
  @HiveField(2)
  other,             // Report something else
  @HiveField(3)
  block,             // Block
}

/// 举报实体
@HiveType(typeId: 8)
class ReportEntity extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  final String reporterId; 

  @HiveField(2)
  final String targetId;

  @HiveField(3)
  final ReportType type;

  @HiveField(4)
  final ReportReason reason;

  @HiveField(5)
  final DateTime timestamp;

  @HiveField(6)
  final String? description;

  ReportEntity({
    required this.id,
    required this.reporterId,
    required this.targetId,
    required this.type,
    required this.reason,
    required this.timestamp,
    this.description,
  });

  factory ReportEntity.fromJson(Map<String, dynamic> json) {
    return ReportEntity(
      id: json['id'] as String,
      reporterId: json['reporterId'] as String,
      targetId: json['targetId'] as String,
      type: ReportType.values[json['type'] as int],
      reason: ReportReason.values[json['reason'] as int],
      timestamp: DateTime.parse(json['timestamp'] as String),
      description: json['description'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'reporterId': reporterId,
      'targetId': targetId,
      'type': type.index,
      'reason': reason.index,
      'timestamp': timestamp.toIso8601String(),
      'description': description,
    };
  }

  @override
  String toString() {
    return 'ReportEntity(id: $id, reporterId: $reporterId, targetId: $targetId, type: $type, reason: $reason, timestamp: $timestamp)';
  }
}

extension ReportReasonExtension on ReportReason {
  String get displayText {
    switch (this) {
      case ReportReason.sexuallyExplicit:
        return 'Sexually Explicit Material';
      case ReportReason.spam:
        return 'Spam';
      case ReportReason.other:
        return 'Something else';
      case ReportReason.block:
        return 'Block';
    }
  }
}

extension ReportTypeExtension on ReportType {
  String get displayText {
    switch (this) {
      case ReportType.post:
        return 'Post';
      case ReportType.user:
        return 'User';
      case ReportType.chat:
        return 'Chat';
    }
  }
}
